const exp = require('express'),
    util = require('../utilities'),
    db = require('../db');

const router = exp.Router()

router.get('/api/data', (req, res) => {
    db.Question
        .find().sort({ _id: -1 }).select(' time title _id')
        .exec((err, data) => {
            if (err) {
                // 
            } else {
                var questions = [];
                res.json({
                    Data: {
                        Time: new Date(),
                        questions: data.map(m => {
                            m = m.toObject();
                            m.id = m._id.toString();
                            delete m._id;
                            return m;
                        })
                    }
                });
            }
        });
});


module.exports = router